﻿<script type="text/javascript">
    //Sort
    $("#all-rentals a.sort-method").click(function () {
        var sortMethod = $(this).text();
        $.post("/Rental/FilterAllRentals?sort=" + sortMethod + "&incFilter=" + allFilterSubmit, $("#all-rentals-filter-form").serialize(), function (data) {
            $("#all-rentals-list").html(data);
        });
    });

    //Don't included idle filter values if not submitted
    var allFilterSubmit = false;

    //Hide Filter-Form after Submit
    $("#all-rentals-filter-form").submit(function () {
        allFilterSubmit = true;
        $("#filter-link").click();
    });

    //Visual toggle for Filter-Form
    $("#filter-link").click(function() {
        $(this).toggleClass("active");
        
        if($(this).hasClass("active")) {
            $(this).find(".arrow").removeClass("right").addClass("down-alt");
        }
        else {
            $(this).find(".arrow").removeClass("down-alt").addClass("right");
        }

        $("#all-rentals #filter").toggle();
    });
</script>

<div id="filter-link"><a href="#" style="float: left;">Apply Filter</a><span class="arrow right" style="float: left;"></span></div>
<div id="filter">
    @using (Ajax.BeginForm("FilterAllRentals", "Rental", new { incFilter = "true" }, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "all-rentals-list" }, new { id = "all-rentals-filter-form" }))
    {
        @Html.ValidationSummary(true)
        
        @Html.Action("Filter")
    }
</div>

<table width="100%" id="all-rentals-list-headings">
    <tr>
        <td width="40"></td>
        <td width="175"><a href="#" class="sort-method">Name</a>/<a href="#" class="sort-method">Address</a>&nbsp;&nbsp;<a href="#" class="sort-method">Bed</a>/<a href="#" class="sort-method">Bath</a></td>
        <td width="140"><a href="#" class="sort-method">Email</a>/<a href="#" class="sort-method">Phone</a></td>
        <td width="50"><a href="#" class="sort-method">Rent</a>/<a href="#" class="sort-method">Deposit</a></td>
        <td></td>
    </tr>
</table>

<div id="all-rentals-list">
    @Html.Action("FilterAllRentals")
</div>